package com.xinghen.ace.common.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author xinghen
 * @ClassName: RestResult
 * @Package: com.xinghen.ace.common.response
 * @Description 用于封装返回结果
 * @create 2018-05-04 10:58
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RestResult<T> {

    /**
     * 成功码
     */
    public static final int SUCCESS_CODE = 200;

    /**
     * 服务器内部错误码
     */
    public static final int SERVER_ERROR_CODE = 500;

    /**
     * 状态码
     */
    private int code = SUCCESS_CODE;

    /**
     * 返回消息
     */
    private String message;

    /**
     * 返回数据
     */
    T data;

    public static <T> RestResult<T> ok() {
        return ok(null);
    }

    public static <T> RestResult<T> ok(T data) {
        return new RestResult<>(SUCCESS_CODE, null, data);
    }

    public static <T> RestResult<T> error(int code, String message) {
        return new RestResult<>(code, message, null);
    }

    public static <T> RestResult<T> error(String message) {
        return error(SERVER_ERROR_CODE, message);
    }

}
